﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestlifeInsertUserDataAction : BestLifeDataAction<int>
    {
        private User GvUser;
        public BestlifeInsertUserDataAction(User PUser)
        {
            GvUser = PUser;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertUser";

                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvUser.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Use_Type", GvUser.Use_Type.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Use_Name", GvUser.Use_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Pas_Word", GvUser.Pas_Word.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Access", GvUser.User_Access.ToString()));
               
                LvCommand.Parameters.Add(new SqlParameter("@Use_Id", GvUser.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvUser.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvUser.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvUser.Last_Modify.ToString())));

                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 
            
            }
            catch(BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }

        }
    }
}
